<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/include.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="<%=basePath%>/css/pager.css" rel="stylesheet">
<script src="<%=basePath%>/js/jquery.js"></script>
<script src="<%=basePath%>/js/jquery.form.js"></script>
<script src="<%=basePath%>/js/jquery.pager.js"></script>
<script language="JavaScript" type="text/javascript"
	src="<%=basePath%>/js/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	$(document).ready(function() {

		var userpage = "";
		$("#userpage").empty();
		var start = 1;
		if ('${page.currentPage}' > 3 && '${page.currentPage}' <= ('${page.pageCount}' - 2)) {
			start = ('${page.currentPage}' - 2);
		}
		if (('${page.currentPage}' >= ('${page.pageCount}' - 2)) && ('${page.currentPage}' <= '${page.pageCount}')) {
			start = ('${page.pageCount}' - 4);
		}
		var end = 5;
		if (('${page.currentPage}' > 3) && ('${page.currentPage}' < ('${page.pageCount}' - 2))) {
			end = ('${page.currentPage}' + 2);
		}
		if (('${page.currentPage}' >= ('${page.pageCount}' - 2)) && ('${page.currentPage}' <= '${page.pageCount}')) {
			end = '${page.pageCount}';
		}
		if ('${page.pageCount}' < 5) {
			start = 1;
			end = '${page.pageCount}';
		}
		if ('${page.pageCount}' == 0) {
			end = 1;
		}
		userpage += "<div class=\"page\"><span class=\"b3\"><a href=\"#\" onclick=\"startPage(1);\">首页</a></span><b class=\"b4\">"
		if ('${page.currentPage}' > 1) {
			userpage += "<a href=\"#\" onclick=\"startPage(" + ('${page.currentPage}' - 1) + ");\">&lt;</a>";
		}
		for ( var index = start; index <= end; index++ ) {
			userpage += "<span class=\"b5\"><a onclick=\"startPage(" + (index) + ");\" href='#'";

			if (index == '${page.currentPage}') {
				userpage += "class='last'";
			}
			userpage += ">" + index + "</a></span>";
		}
		userpage += "</b><b class=\"b4\">";
		if ('${page.pageCount}' > '${page.currentPage}') {
			userpage += "<a href=\"#\" onclick=\"startPage(" + ('${page.currentPage}' + 1) + ");\" >&gt;</a>";
		}
		userpage += "</b><span class=\"b3\"><a href=\"#\" onclick=\"startPage('" + ${page.pageCount} + "');\">末页</a></span></div>";
		$("#userpage").append(userpage);
		
	});
	
	function startPage(start){
		$("#start").val(start);
		$('#selForm').submit();
	}
	//function delUser(id){
		// $.ajax({
			//type : 'post',//可选get
			//url : '/user/delUser/' + id,
			//dataType:'text',//服务器返回的数据类型 
			//success : function(msg) {
				//json = eval("["+json+"]");
				//$.each(json, function (i, o) {
					//alert(o.id);
				//})
		//	},
			//error : function() {
		//		alert(111);
		//	} 
		//}) 
//	}
	
	//ajax提交操作
	function delUser(id){
		$.ajax({
			type : 'post',//可选get
			url : '<%=basePath%>/user/delUser/' + id ,
			//data : 'userName='+$("#userName").val()+'&id='+$("#id").val(),
			dataType : 'text' ,//服务器返回的数据类型 
			success : function(msg) {
				alert(msg);
				$('#selForm').submit();
			} ,
			error : function() {
				alert(msg);
			}
		})
	}
</script>
</head>
<body>
	<table id="dataTable" width="100%" border="0" cellspacing="0" cellpadding="2">
		<form id="selForm" name="selForm" action="<%=basePath%>/user/selUser" method="post">
			<thead>
				<tr>
					<input type="hidden" id="start" name="start" value="${page.currentPage }" />
					<th>用户名:<input type="text" id="userName" name="userName" value="${user.userName}" /><input
						type="submit" id="_submit"></th>
				</tr>
			</thead>
		</form>
	</table>
	<table id="dataTable" width="100%" border="0" cellspacing="0" cellpadding="2">
		<thead>
			<tr>
				<th>id</th>
				<th>用户名</th>
				<th>密码</th>
				<th>开始时间</th>
				<th>结束时间</th>
				<th>备注</th>
				<th width="150px">操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${page.result}" var="use" varStatus="voStatus">
				<tr>
					<th>${use.id}</th>
					<th>${use.userName}</th>
					<th>${use.passWord}</th>
					<th>${use.startTime}</th>
					<th>${use.endTime}</th>
					<th>${use.remark}</th>
					<th width="150px"><a href="#" onclick="delUser('${use.id}')">删除</a><a
						href="<%=basePath%>/user/edit/${use.id}">更新</a></th>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<table id="dataTable" width="100%" border="0" cellspacing="0" cellpadding="2">
		<thead>
			<tr>
				<th><div id="userpage" class="pager"></div></th>
			</tr>
		</thead>
	</table>

</body>

</html>